from rest_framework import serializers
from .models import Area


class AreaSerializer(serializers.ModelSerializer):
    class Meta:
        model = Area
        fields = ('id', 'name')


class SubAreaSerializer(serializers.ModelSerializer):
    subs = AreaSerializer(many=True, read_only=True)

    class Meta:
        model = Area
        fields = ('id', 'name', 'subs')
        # subs是获取下一级的信息　返回的是数据级，一个一个的对象集合
        # 而我们需要的是字典，所以需要重写subs字段关联一个序列化器拿到具体的数据

